package com.sd.ws;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.util.UUID;


@Configuration
public class WebSocketConfig {
    private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);

   /*websocket:
   https://blog.csdn.net/weixin_38111957/article/details/86352677
   	sfc_platagentinfo("1264","123456", "100000","89Sdfc88@","100000","ws://47.104.94.106:8004/AcdGate/softPhone/")
   FlashAgentX.g_WSUrl = FlashAgentX.g_uri + FlashAgentX.g_TokenId + "/" + FlashAgentX.g_OptId;



//提供crm的外部接口
function sfc_platagentinfo(entId,entPwd, agentid,agentpwd,extension,acgateserverurl){
	FlashAgentX.loadConfig(entId,entPwd,acgateserverurl,acgateserverurl,agentid,agentpwd,extension);
}

function sfc_platagentinfo(entId,entPwd, agentid,agentpwd,extension,acgateserverurl){
sfc_platagentinfo("1264","123456", "100002","89Sdfc88@","100002","ws://47.104.94.106:8004/AcdGate/softPhone/")
FlashAgentX.loadConfig(entId,entPwd,acgateserverurl,acgateserverurl,agentid,agentpwd,extension);
FlashAgentX.loadConfig = function(entId,entPwd, masterUri, slaveUri, agentId, agentPwd, extNum) {
    try {
        FlashAgentX.g_TokenId = FlashAgentX.uuid();
        //alert("这里测试acdgate,生产环境须注释掉 maserturi=...");
        // masterUri = "ws://127.0.0.1:8080/AcdGate/softPhone/" ;
        //masterUri = "ws://cloudcall.58.com:1931/AcdGate/softPhone/" ;
        //slaveUri = "ws://cloudcall.58.com:1930/AcdGate/softPhone/" ;
        //    masterUri = "ws://cloudcall.58.com:1936/AcdGate/softPhone/" ;
        //  alert("注意：投产时 masterUri 须注释");
        // masterUri = "ws://10.245.2.106:8081/AcdGateBeta/softPhone/";
        console && console.log ("您当前绑定分机:" + g_AcdInfo.extNum );
        FlashAgentX.g_masterUri = masterUri;
        FlashAgentX.g_slaveUri = slaveUri;
        FlashAgentX.g_uri = masterUri;
        FlashAgentX.g_OptId = agentId;
        //if(extNum!=null && extNum!=""){
        	FlashAgentX.g_extNum = extNum;
        //}else{
        //	FlashAgentX.g_extNum = agentId;
        //}
        FlashAgentX.g_entId = entId;
        FlashAgentX.g_entpwd = entPwd;
        FlashAgentX.g_agentPwd = agentPwd;
        FlashAgentX.g_WSUrl = FlashAgentX.g_uri + FlashAgentX.g_TokenId + "/" + FlashAgentX.g_OptId;
        if (!FlashAgentX.isConnected) {
            FlashAgentX.connect();
            setTimeout(function() {
                FlashAgentX.checkin();
            }, 1000);
        }
        console.log(FlashAgentX.g_WSUrl);
        FlashAgentX.loaded = true ; //参数加载成功
    } catch(e) {
        console.log('连接出错:' + e + ",url:" + FlashAgentX.g_WSUrl);
    }

}
   */

  /*  @Bean
    public WebSocketClient webSocketClient(){
     try {
         String g_uri = "ws://47.104.94.106:8004/AcdGate/softPhone/";
         String g_TokenId = UUID.randomUUID().toString();
         String g_OptId = "100002";
         String g_WSUrl = g_uri + g_TokenId + "/" + g_OptId;
         System.out.println("g_WSUrl:"+g_WSUrl);
         WebSocketClient webSocketClient = new WebSocketClient(new URI(g_WSUrl),new Draft_6455()){
             @Override
             public void onOpen(ServerHandshake serverHandshake) {
                 log.info("[websocket] 连接成功");
             }

             @Override
             public void onMessage(String message) {
                 log.info("[websocket] 收到消息={}",message);
             }

             @Override
             public void onClose(int i, String s, boolean b) {
                 log.info("[websocket] 退出连接");
             }

             @Override
             public void onError(Exception ex) {
                 log.info("[websocket] 连接错误={}",ex.getMessage());
             }
         };
         webSocketClient.connect();
         return webSocketClient;
     }catch (Exception e){
         e.printStackTrace();
         return null;
     }
    }*/
}
